extends "res://Weapon/scripts/WeaponCommon.gd"
	
# 扇形扩散枪

@onready var bullet = load("res://Bullet/tscn/Bullet.tscn")

# 可调参数
@export var diffuseNum = 8			## 散射子弹数量
@export var diffuseAngle = 30		## 散射角度, 值越大子弹越分散

'''
	开火
'''
func fire():
	power = bulletPower * state.power
	if !isFire:
		audio.play()
		fireTimer.start()
		
		# 基础方向
		var baseDirection = (get_global_mouse_position() - global_position).normalized()
		
		# 生成散射子弹
		for i in range(diffuseNum):
			var bullet = self.bullet.instantiate()
			bullet.speed = self.bulletSpeed
			bullet.power = self.power
			bullet.position = shootPosition.global_position
			
			# 计算角度偏移（-15° 到 +15° 均匀分布）
			var angleOffset = deg_to_rad(diffuseAngle) * (i / float(diffuseNum - 1) - 0.5)
			
			# 应用旋转后的方向
			bullet.direction = baseDirection.rotated(angleOffset)
			get_tree().root.add_child(bullet)
		
		isFire = true


